import datetime as dt
import uuid

import pytest

from recruit.domain.models.resume_work import (
    BaseResumeWork,
    ResumeWorkCreate,
    ResumeWorkResult,
    ResumeWorkUpdate,
)
from .utils import check_attr_model, check_json_schema


def invalid_data() -> list[dict[str, str | int]]:
    return [
        {
            'start_work': 2010,
            'end_work': '2009',
            'position': 'position',
            'company': 'company',
            'workplace': 'workplace'
        },
        {
            'start_work': 2010,
            'end_work': str(dt.datetime.now().year + 1),
            'position': 'position',
            'company': 'company',
            'workplace': 'workplace'
        }
    ]


@pytest.mark.parametrize(
    'data, keys', [(
            {
                'start_work': 2010,
                'end_work': '2020',
                'position': 'position',
                'company': 'company',
                'workplace': 'workplace'
            },
            ('startWork', 'endWork', 'position', 'company', 'workplace')
    )]
)
def test_resume_work_base(
        data: dict[str, str | int],
        keys: tuple[str, ...]
) -> None:
    check_attr_model(BaseResumeWork, data)
    check_json_schema(BaseResumeWork, keys)


@pytest.mark.parametrize('data', invalid_data())
def test_validate_in_resume_work_base(
        data: dict[str, str | int]
) -> None:
    with pytest.raises(ValueError):
        BaseResumeWork(**data)


@pytest.mark.parametrize(
    'data, keys', [(
            {
                'start_work': 2010,
                'end_work': '2020',
                'position': 'position',
                'company': 'company',
                'workplace': 'workplace'
            },
            ('startWork', 'endWork', 'position', 'company', 'workplace')
    )]
)
def test_resume_work_create(
        data: dict[str, str | int],
        keys: tuple[str, ...]
) -> None:
    check_attr_model(ResumeWorkCreate, data)
    check_json_schema(ResumeWorkCreate, keys)


@pytest.mark.parametrize('data', invalid_data())
def test_validate_in_resume_work_create(
        data: dict[str, str | int]
) -> None:
    with pytest.raises(ValueError):
        ResumeWorkCreate(**data)


@pytest.mark.parametrize(
    'data, keys', [(
            {
                'id': uuid.uuid4(),
                'start_work': 2010,
                'end_work': '2020',
                'position': 'position',
                'company': 'company',
                'workplace': 'workplace'
            },
            ('id', 'startWork', 'endWork', 'position', 'company', 'workplace')
    )]
)
def test_resume_work_create(
        data: dict[str, str | int],
        keys: tuple[str, ...]
) -> None:
    check_attr_model(ResumeWorkResult, data)
    check_json_schema(ResumeWorkResult, keys)


@pytest.mark.parametrize(
    'data, keys', [(
            {
                'start_work': 2010,
                'end_work': '2020',
                'position': 'position',
                'company': 'company',
                'workplace': 'workplace'
            },
            ('startWork', 'endWork', 'position', 'company', 'workplace')
    )]
)
def test_resume_work_update(
        data: dict[str, str | int],
        keys: tuple[str, ...]
) -> None:
    check_attr_model(ResumeWorkUpdate, data)
    check_json_schema(ResumeWorkUpdate, keys)
    check_attr_model(ResumeWorkUpdate, {}, tuple(data))
    check_json_schema(ResumeWorkUpdate, keys)
